//
//  FKInputOrderSnVC.m
//  WanTao
//
//  Created by Macbook Pro on 2019/4/3.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKInputOrderSnVC.h"
#import "FKChooseLogisticsVC.h"

@interface FKInputOrderSnVC ()

@property (weak, nonatomic) IBOutlet UITextField *orderSnField;
@property (weak, nonatomic) IBOutlet UITextField *companyField;
@property (weak, nonatomic) IBOutlet UITextField *logisticsSnField;

@property (nonatomic, strong) NSMutableDictionary *param;

@end

@implementation FKInputOrderSnVC

- (NSMutableDictionary *)param
{
    if (!_param) {
        _param = [NSMutableDictionary dictionary];
    }
    return _param;
}

- (instancetype)init
{
    return [UIStoryboard storyboardWithName:@"FKInputOrderSnVC" bundle:nil].instantiateInitialViewController;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.orderSnField.text = self.refund_sn;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addOtherLogistic:) name:@"addOtherLogistic" object:nil];
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)addOtherLogistic:(NSNotification *)noti
{
    NSDictionary *dict = noti.userInfo;
    self.companyField.text = dict[@"name"];
    self.param[@"express"] = dict[@"name"];
    self.param[@"express_com"] = dict[@"code"];
}


- (IBAction)confirmBtnClicked:(UIButton *)sender
{
    if (self.companyField.text.length == 0) {
        [SVProgressHUD showInfoWithStatus:self.companyField.placeholder];
        return;
    }
    if (self.logisticsSnField.text.length == 0) {
        [SVProgressHUD showInfoWithStatus:self.logisticsSnField.placeholder];
        return;
    }
    
    self.param[@"order_refund_id"] = self.order_refund_id;
    self.param[@"express_sn"] = self.logisticsSnField.text;
    [FKHttpTool postWithSuffix:@"/OrderRefund/userShip" param:self.param success:^(FKBaseResult *result) {
        if (result.isSuccess) {
            [SVProgressHUD showSuccessWithStatus:@"提交成功"];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshOrderListVC" object:nil];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshRefundDetailVC" object:nil];
            fkPopVC;
        }
    } failure:nil];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 1) {
        FKChooseLogisticsVC *vc = [[FKChooseLogisticsVC alloc] init];
        vc.order_refund_id = self.order_refund_id;
        fkPushNav(vc);
        fkWeakSelf(self);
        vc.chooseLogisticBlock = ^(NSDictionary * _Nonnull dict) {
            weakself.companyField.text = dict[@"name"];
            weakself.param[@"express"] = dict[@"name"];
            weakself.param[@"express_com"] = dict[@"code"];
        };
    }
}


@end
